import cn.hutool.core.util.HexUtil;
import com.mach.platform.sprider.dev.ByteUtil;
import com.mach.platform.sprider.dev.DataHelper;
import com.mach.platform.sprider.dev.UU;

import java.io.IOException;

public class PlcReader {

    public static void main(String[] args) throws IOException {


        String ip = "192.168.2.16";
        int port = 502;

        DataHelper dataHelper = new DataHelper(ip, port, 1);

        byte[] dataTcp = dataHelper.getDataTcp(19, 2);
        byte[] subData = ByteUtil.subData(dataTcp, 9, 4);
        System.out.println("back data:");
        UU.printData(dataTcp);
        System.out.println("sub datas:"+ HexUtil.encodeHexStr(subData));
        UU.printData(subData);
//        int parseUnsignedInt = Integer.parseUnsignedInt("0115D1A3",16);
//        System.out.println("=====");
//        System.out.println(parseUnsignedInt);
        // REAL --> float
        // DINT --> 新增
        // BOOL -->
        // INT  --> short
        // DWORD --> short
        Object aFloat = UU.bytes2Value("short", subData);
        System.out.println("result:" +aFloat);


    }

}
